package com.itheima.demo;

import com.itheima.domain.Emp;
import com.itheima.mapper.EmpMapper;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.omg.PortableInterceptor.INACTIVE;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Demo {
    /*public static void main(String[] args) throws Exception{
        InputStream is = Resources.getResourceAsStream("sql.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession session = factory.openSession();
        EmpMapper mapper = session.getMapper(EmpMapper.class);
        List<Emp> list = mapper.findById(1);
        System.out.println(list);
        session.commit();
        is.close();
        session.close();
    }*/

    @Test
    public void test1() throws Exception {
        SqlSession session = MapperUtil.getSession();
        EmpMapper mapper = session.getMapper(EmpMapper.class);
        List<Emp> list = mapper.findById(7369);
        System.out.println(list);
        MapperUtil.close(session);
    }

    @Test
    public void test2() throws Exception {
        EmpMapper mapper = MapperUtil.getMapper(EmpMapper.class);
        List<Emp> list = mapper.findById(7369);
        System.out.println(list);
    }

    @Test
    public void test3() throws Exception {
        EmpMapper mapper = MapperUtil.getMapper(EmpMapper.class);
        List<Emp> list = mapper.dynamicFindById(7369);
        System.out.println(list);
    }

    @Test
    public void test4() throws Exception {
        EmpMapper mapper = MapperUtil.getMapper(EmpMapper.class);
        mapper.update("李四",1000,null,1);
    }

    @Test
    public void test5() throws Exception {
        EmpMapper mapper = MapperUtil.getMapper(EmpMapper.class);
        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(7369);
        list.add(2);
        mapper.findWithId(list);
    }
}
